package com.sgb.kjwl.view.widget;

import android.content.Context;

import androidx.annotation.ColorInt;
import androidx.recyclerview.widget.GridLayoutManager;

import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.PickSelectEntity2;
import com.sgb.kjwl.view.ui.adapter.enterprise.CirclePickSelectAdapter;
import com.swgk.core.dialog.PopViewHolder;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;

import java.util.List;

public class NormalPopWindow<D extends PickSelectEntity2> extends BasePopWindow<D> {
    private CirclePickSelectAdapter<D> adapter;
    private MaxHeightRecyclerView recyclerView;

    public NormalPopWindow(Context context) {
        super(context);
    }

    @Override
    protected int popLayout() {
        return R.layout.popwindow_for_manage;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        recyclerView = holder.getPop().findViewById(R.id.goods_type_list);

        adapter = new CirclePickSelectAdapter<>(mContext, null);
        adapter.setItemSelect(true);
        adapter.setDefItem(0);
        recyclerView.setLayoutManager(new GridLayoutManager(mContext, 4));
        recyclerView.setAdapter(adapter);

        adapter.setOnItemClick(new AdapterOnItemClick<D>() {
            @Override
            public void onItemClick(D ipPickSelectEntity, int position) {
                onResultClick.result(ipPickSelectEntity, position, null);
                dissMiss();
            }
        });

        holder.getPop().findViewById(R.id.bg_pop_gray_layout).setOnClickListener(view -> dissMiss());
    }

    @Override
    public void setData(List<D> list) {
        adapter.setDatas(list);
    }

    @Override
    protected List<D> getData() {
        return adapter.getDatas();
    }


    public void setDefItem(int position) {
        adapter.setDefItem(position);
    }

    public void setBackGround(@ColorInt int color){
        recyclerView.setBackgroundColor(color);
    }
}
